package cn.shop.dys.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import cn.shop.dys.R;

/**
 * 作者：jian on 2016/4/21 12:49
 * 孙建
 */
public class ProductImageView extends FrameLayout implements View.OnClickListener {
    private OnClickSmallImageViewListener mListener;
    private ImageView mIvCart;
    private TextView mTvPrice;

    public ProductImageView(Context context) {
        this(context,null);
    }

    public ProductImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        View.inflate(getContext(), R.layout.search_product_img_layout,this);
        mIvCart = (ImageView) findViewById(R.id.iv_cart);
        mTvPrice = (TextView) findViewById(R.id.tv_price);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ProductImageView);
        String price = typedArray.getString(R.styleable.ProductImageView_text_product_price);
      //  int resourceId = typedArray.getResourceId(R.styleable.ProductImageView_img_product_background, R.drawable.recommend_product1);
        Drawable drawable = typedArray.getDrawable(R.styleable.ProductImageView_img_product_background);
        if(drawable!=null){
            setBackgroundDrawable(drawable);
        }
        if(TextUtils.isEmpty(price)){
            price="250";
        }
        typedArray.recycle();
    //    setBackgroundResource(resourceId);
        mTvPrice.setText(price);
        mIvCart.setOnClickListener(this);
     //   init();
    }
    public void setText(String text){
        mTvPrice.setText(text);
    }
    @Override
    public void onClick(View v) {
        if(mListener!=null){
            mListener.onClick(v);
        }
    }
    public void setOnClickSmallImageViewListener(OnClickSmallImageViewListener mListener){
        this.mListener=mListener;
    }
    public interface OnClickSmallImageViewListener{
        void onClick(View v);
    }
   /* public ProductImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }*/

    /*private void init() {

    }*/
}
